package com.spoto.oa.service.impl;

import java.sql.SQLException;
import java.sql.Date;
import java.util.List;

import com.spoto.oa.dao.SalesDao;
import com.spoto.oa.dao.impl.SalesDaoImpl;
import com.spoto.oa.model.Sales;
import com.spoto.oa.service.SalesServ;

public class SalesServImpl implements SalesServ {

	SalesDao salesDao = new SalesDaoImpl();

	public void addSales(Sales sales) throws SQLException {
		salesDao.addSales(sales);
	}

	public List<Sales> getSales(String type, String value, String creator,
			boolean role) {
		List<Sales> salesList = null;
		if (value.equals("") || type.equals("")) {
			return salesDao.getAllSales(creator, role);
		}
		if (type.equals("proType")) {
			salesList = salesDao.getSalesByProType(value, creator, role);
		} else if (type.equals("proCode")) {
			salesList = salesDao.getSalesByProCode(value, creator, role);
		}
		return salesList;
	}

	public List<Sales> getSalesByTime(Date dateBegin, Date dateEnd) {
		// TODO Auto-generated method stub
		return null;
	}

	public void updateSales(int id, Sales sales) {
		salesDao.updateSales(id, sales);
	}

	public void setInvalid(int id) {
		salesDao.setInvalid(id);		
	}

	public List<Sales> getSalesByTime(Date dateBegin, Date dateEnd,
			String creator, boolean role) {
		return salesDao.getSalesByTime(dateBegin, dateEnd, creator, role);
	}

	public List<Sales> getSalesByTime(Date dateBegin, Date dateEnd,
			String proType, String creator, boolean role) {
		return salesDao.getSalesByTime(dateBegin, dateEnd, proType, creator, role);
	}


}
